<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
    <link rel="stylesheet" href="../assets/app/css/app.css" />
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/jquery.form.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<body>

<section class="common-section" style="margin-top:0px !important;">
<div class="scroller reset-pwd">
<div class="block20"></div>
<form class="" method="post">
	<ul>

		<li>
			<span>手机号码：</span>
			<input type="text" name="mobile"  placeholder="请输入绑定的手机号" id="mobile" />
		</li>
		

		
		<li>
			<span>输入动态码：</span>
			<input type="text" name="active" placeholder="短信查收" id="active" />
			<span class="get_active">点击获取</span>
		</li>

		<li>
			<span>旧密码：</span>
			<input type="password" placeholder="请输入旧密码" name="pwd1" id="password" />
		</li>
		<li>
			<span>登录密码：</span>
			<input type="password" placeholder="请输入新密码" name="pwd2" id="password" />
		</li>
		<li>
			<span>确认密码：</span>
			<input type="password" placeholder="请重复新密码" name="pwd3" id="notpassword" />
		</li>
	</ul>
<button class="btn btn-positive btn-block login-btn reset-pwd-btn" style="font-size:18px;padding:7px 0;width:50%;margin:0 auto;">确认</button>
  
</form>
<div class="clear"></div>

</div>
</section>
<script>
apiready = function(){
$(function(){
    var userinfo = localData.get('userinfo');
    var userinfo = JSON.parse(userinfo);
    if(userinfo != undefined && userinfo != '' && userinfo != null){
		var pwd1 = $('input[name=pwd1]');
		var pwd2 = $('input[name=pwd2]');
		var pwd3 = $('input[name=pwd3]');
		var active_code = $('input[name=active]');
		var flag = false;
		$('.get_active').click(function(){
			var mobile = $('#mobile').val();
			if(mobile == ''){
				$.PageDialog.fail("请输入手机号码");
				return;
			}
			if(flag == true){
				return;
			}
			flag = true;
			var time = 60;
			$(this).html('60 秒');
			var _this = $(this);
			$(this).css('background','#ccc');
			setId = setInterval(function(){
				time--;
				if(time <= 0){
					_this.css('background','#db3f95');
					_this.html('重新获取');
					flag = false;
					clearInterval(setId);
					return;
				}
				_this.html(time+' 秒');
			},1000);
			$.ajax({
				type : 'POST',
				url : config.url+'/app.php?act=setpwdsendcode&uid='+userinfo['uid'],
				data : {
					'mobile' : mobile
				},
				beforeSend : function(xhr){
					
				},
				success : function(data){
					if(data['status'] == 1){
						$.PageDialog.ok(data['msg']);
					}else if(data['status'] == 9){
						clearInterval(setId);
						_this.html('点击获取');
						flag = true;
						$.PageDialog.ok(data['msg']);
					}else{
						$.PageDialog.fail(data['msg']);
					}
				}
			});
		});
		
		$('.login-btn').click(function(){
			var post = {
				password : pwd1.val(),
				userpassword : pwd2.val(),
				userpassword2 : pwd3.val(),
				active_code : active_code.val()
			};
			if ( post.password == '' ) {
				$.PageDialog.fail('旧密码不能为空哦');
				return false;
			}
			if ( post.userpassword == '' ) {
				$.PageDialog.fail('新密码不能为空哦');
				return false;
			}
			if ( post.userpassword != post.userpassword2 ) {
				$.PageDialog.fail('两次新密码输入不一致哦');
				return false;
			}
			if ( post.userpassword2.length < 6 || post.userpassword2.length > 20) {
				$.PageDialog.fail('密码长度为6-20个字符！');
				return false;
			}
			$.ajax({
				type : 'POST',
				url : config.url+"/app.php?act=setpassword&uid="+userinfo['uid'],
				beforeSend : function(){
					$.PageDialog.ok('正在提交');
					//api.showProgress({title : '正在修改...',text : ''});
				},
				data : post,
				success : function(data){
					if(data['status'] == 1){
						localData.remove('userinfo');
						api.alert({msg:data['msg']},function(index,err){
							randomSwitchBtn('login',api);
							api.closeWin({name:'setpwd'});
						});
					}else{
						$.PageDialog.fail(data['msg']);
					}
				},
			});
			return false;
		});
    }else{
    	randomSwitchBtn('login',api);
    }
});
};
</script>
</body>
</html>